#include "pane.h"
#include "SDL.h"
#include "SDL_Draw.h"
#include <list>
#include <boost/shared_ptr.hpp>

pane::pane(){
	std::string type = "pane";
m_area.x=100;
m_area.y=10;
m_area.h=100;
m_area.w=100;
color=0xaaaaaa;

m_surface=NULL;
m_dragable=true;
m_isClicked=false;
}
pane::pane(widget* nparent){
	std::string type = "pane";
SDL_Rect tArea=nparent->GetRect();
m_surface=nparent->GetSurface();
m_area.x=tArea.x+10;
m_area.y=tArea.y+10;
m_area.h=100;
m_area.w=10;
m_parent=nparent;
color=0xaaaaaa;
m_dragable=true;
m_isClicked=false;
}
void pane::Draw(){
	
	if (m_isClicked==true)
		color = 0xfafafa;
	else
	color = 0xaaaaaa;

	Draw_FillRect(m_surface, m_area.x,m_area.y,m_area.w,m_area.h,color);
	Draw_Rect(m_surface, m_area.x,m_area.y,m_area.w,m_area.h,color-0x404040);
	Draw_Rect(m_surface, m_area.x+1,m_area.y+1,m_area.w-2,m_area.h-2,color-0x202020);

	std::list<boost::shared_ptr<widget>>::iterator end = m_children.end();
	std::list<boost::shared_ptr<widget>>::iterator iter = m_children.begin();
	while (iter!=end){
		(*iter)->Draw();
		iter++;
	}

}

void pane::SetParent(widget* nparent){
	m_parent = nparent;
	m_surface = nparent->GetSurface();
	m_area.x=nparent->GetRect().x+10;
	m_area.y=nparent->GetRect().y+10;
}
widget* pane::GetParent(){return m_parent;}
std::list<boost::shared_ptr<widget>> pane::GetChildren(){return m_children;};
void pane::AddChild(widget*){};
void pane::RemoveChild(widget*){};
SDL_Surface* pane::GetSurface(){return m_surface;};
SDL_Rect pane::GetRect(){return m_area;};
void pane::SetRect(SDL_Rect a){m_area=a;}

bool pane::IsHovered(int x,int y){

	if (( x>m_area.x && x<(m_area.x+m_area.w))&&( y>m_area.y && y<(m_area.y+m_area.h))){
		return true;
	}
	return false;


}
bool pane::GetClicked(){
	return m_isClicked;
}
void pane::SetClicked(bool b){
	m_isClicked = b;
}